﻿#Region "Copyright"
'————————————————————————————————————————
'	创建人员(Creator)    ：Huangyd
'	创建日期(Date)       ：2012-07-14
'   联系方式(Email)      ：aj-ayumi@163.com; gajayumi@gmail.com; ajayumi@me.com
'   描    述(Description)：
'
'	Copyright (C) 2012 ajayumi 版权所有
'————————————————————————————————————————
#End Region
Imports System.Runtime.InteropServices

Namespace WinAPI

    Public Class Kernal32Dll
        ''' <summary>
        ''' 调用控制台窗口
        ''' </summary>
        ''' <returns></returns>
        <DllImport("kernel32.dll")> _
        Public Shared Function AllocConsole() As Boolean
        End Function

        ''' <summary>
        ''' 释放控制台窗口
        ''' </summary>
        ''' <returns></returns>
        <DllImport("kernel32.dll")> _
        Public Shared Function FreeConsole() As Boolean
        End Function

        <DllImport("kernel32.dll", CharSet:=CharSet.Unicode)> _
        Public Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr
        End Function

        <DllImport("kernel32.dll", CharSet:=CharSet.Unicode)> _
        Public Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr
        End Function

        <DllImport("kernel32.dll", CharSet:=CharSet.Ansi, exactspelling:=True)> _
        Public Shared Function GetProcAddress(ByVal hModule As IntPtr, ByVal procName As String) As IntPtr
        End Function

        <DllImport("kernel32.dll")> _
        Public Shared Function GetCurrentThreadId() As UInteger
        End Function

        <DllImport("kernel32.dll")> _
        Public Shared Function OpenProcess(ByVal dwDesiredAccess As Integer, _
                                  ByVal bInheritHandle As Integer, _
                                  ByVal dwProcessId As Integer) As Integer

        End Function

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="hProcess">进程，如果你是做外挂的话，它代表你要挂的那个游戏。</param>
        ''' <param name="lpBaseAddress">你要读取的内存地址</param>
        ''' <param name="lpBuffer">从上面那个参数地址里读出来的东西(调用这个函数的就是为了它)  不管这个参数是什么类型，它应该是一个数组，否则读不出东西来</param>
        ''' <param name="nSize">长度，上一个参数，类型是int，那个长度应该用4</param>
        ''' <param name="lpNumberOfBytesWritten">用0就行了</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <DllImport("kernel32.dll")> _
        Public Shared Function ReadProcessMemory(ByVal hProcess As Integer, _
                                             ByVal lpBaseAddress As Integer, _
                                             ByRef lpBuffer As Integer, _
                                             ByVal nSize As Integer, _
                                             ByRef lpNumberOfBytesWritten As Integer) As Integer
        End Function

        <DllImport("kernel32.dll")> _
        Public Shared Function ReadProcessMemory(ByVal hProcess As Integer, _
                                         ByVal lpBaseAddress As Integer, _
                                         ByRef lpBuffer() As Byte, _
                                         ByVal nSize As Integer, _
                                         ByRef lpNumberOfBytesWritten As Integer) As Integer
        End Function

        <DllImport("kernel32.dll")> _
        Public Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, _
                                     ByVal lpBaseAddress As IntPtr, _
                                     ByRef lpBuffer As IntPtr, _
                                     ByVal nSize As Int32, _
                                     ByRef lpNumberOfBytesWritten As Int32) As Boolean

        End Function

        <DllImport("kernel32.dll")> _
        Public Shared Function CloseHandle(ByVal hProcess As Integer) As Integer
        End Function

        <DllImport("kernel32", CharSet:=CharSet.Auto, SetLastError:=True)> _
        Public Shared Function VirtualProtectEx(ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As IntPtr, ByVal flNewProtect As UInteger, ByRef lpflOldProtect As UInteger) As Boolean
        End Function

    End Class


End Namespace
